Post

Replies

Boosts

Views

Activity

LSRegisterURL resultCode -10819
I have an option in my app to set the URL Handler for smb or switch it back to Finder. But using my code below it always give me a -10819 error. Which is a generic kLSNotRegisteredErr, even those the documentation shows "Not currently used." func setDefaultHandler(bundleID: String) { DebugLogger.shared.log("Attempting to set \(bundleID) as default handler for SMB URLs") // Post Sonoma macOS requires user interaction to change default handlers // We'll register our app and then guide the user to System Settings // For our app, register it with Launch Services if bundleID != "com.apple.finder" { if let appBundleURL = Bundle.main.bundleURL as CFURL? { let registerResult = LSRegisterURL(appBundleURL, true) DebugLogger.shared.log("LSRegisterURL result: [\(appBundleURL)]\(registerResult)") } } // Check current handler using modern API let testSMBURL = URL(string: "smb://example.com")! if let handlerURL = NSWorkspace.shared.urlForApplication(toOpen: testSMBURL) { DebugLogger.shared.log("Current default handler is: \(handlerURL)") // Try to get the bundle ID from the URL var currentHandlerBundleID = "" if let bundle = Bundle(url: handlerURL) { if let handlerBundleID = bundle.bundleIdentifier { currentHandlerBundleID = handlerBundleID DebugLogger.shared.log("Current default handler bundle ID: \(handlerBundleID)") } } // Check if the current handler is already what we want let alreadySet = currentHandlerBundleID == bundleID DebugLogger.shared.log("Handler is already set correctly: \(alreadySet)") if alreadySet { let alert = NSAlert() alert.messageText = "Default Handler Status" alert.informativeText = "\(bundleID == "com.apple.finder" ? "Finder" : "LGN") is already set as the default handler for SMB URLs." alert.addButton(withTitle: "OK") alert.runModal() } else { // Guide the user to System Settings to change the handler promptToSetDefaultHandler(bundleID == "com.apple.finder" ? "Finder" : "LGN") } } else { DebugLogger.shared.log("Could not determine current handler") promptToSetDefaultHandler(bundleID == "com.apple.finder" ? "Finder" : "LGN") } }
4
0
325
Mar ’25